package com.audaque.jadmin.system.shiro;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.apache.shiro.web.util.WebUtils;

/**
 * @Description :
 * @FileName: FormAuthenticationCaptchaFilter.java
 * @Author :WeiHui.Zhang
 * @Data : 2015年10月19日 下午4:36:50
 * @Version:V1.00
 */
public class FormAuthenticationCaptchaFilter extends FormAuthenticationFilter {

	public String captcha;

	protected String getCaptcha(ServletRequest request) {
		return WebUtils.getCleanParam(request, getCaptcha());
	}

	@Override
	protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) {
		String username = getUsername(request);
		String password = getPassword(request);
		String captcha = getCaptcha(request);
		boolean rememberMe = isRememberMe(request);
		String host = getHost(request);
		return new UsernamePasswordCaptchaToken(username, password.toCharArray(), rememberMe, host, captcha);
	}

	public String getCaptcha() {
		return captcha;
	}

	public void setCaptcha(String captcha) {
		this.captcha = captcha;
	}

}
